package com.ztspeech.vad;

public class VoiceDetector {
	public static final int SAMPLE_RATE = 16000;
	public static final int FRAME_LEN_MS = 10;
	
	private long hVad = 0;
	
	public VoiceDetector(int mode) {
		hVad = VadJni.vdNewVad(mode);
	}
	
	@Override
	protected void finalize() throws Throwable {
		if (hVad != 0)
			VadJni.vdDelVad(hVad);
		
		super.finalize();
	}

	public boolean reset() {
		return VadJni.vdResetVad(hVad);
	}
	
	public int setParam(int param, int val) {
		return VadJni.vdSetIntParam(hVad, param, val);
	}
	
	public int setParam(int param, float val) {
		return VadJni.vdSetFloatParam(hVad, param, val);
	}
	
	public boolean inputWave(byte[] waveData, int offset, int length, boolean isEnd) {
		return VadJni.vdInputWave(hVad, waveData, offset, length, isEnd);
	}
	
	public int getOffsetFrame() {
		return VadJni.vdGetOffsetFrame(hVad);
	}
	
	public int getVoiceStartFrame() {
		return VadJni.vdGetVoiceStartFrame(hVad);
	}
	
	public int getVoiceStopFrame() {
		return VadJni.vdGetVoiceStopFrame(hVad);
	}
	
	public int getVoiceFrameNum() {
		return VadJni.vdGetVoiceFrameNum(hVad);
	}
	
	public byte[] getVoice(int startFrame, int frameNum) {
		return VadJni.vdGetVoice(hVad, startFrame, frameNum);
	}
}
